package com.itboye.textileexpes.repository;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.textileexpes.beans.ForresterBeans;
import com.itboye.textileexpes.beans.GoodsBean;
import com.itboye.textileexpes.beans.GoodsBean.GoodsList;
import com.itboye.textileexpes.beans.GoodsDetailBean;
import com.itboye.textileexpes.beans.GoodsTopBean;
import com.itboye.textileexpes.interfaces.IGoods;
import com.itboye.textileexpes.json.ByJsonRequest.Builder;
import com.itboye.textileexpres.base.BaseErrorListener;
import com.itboye.textileexpres.base.BaseNetRepository;
import com.itboye.textileexpres.base.BaseSuccessReqListener;

public class GoodsRepository extends BaseNetRepository implements
		IGoods<GoodsBean> {
	static final String FenYeQuery = "By_Product_search";
	static final String KeyWordQuery = "By_Product_searchKeywords";
	static final String DetailQuery = "By_Product_detail";
	static final String AllQuery = "By_Index_index";

	public GoodsRepository(ICompleteListener listener) {
		super(listener);
	}

	@Override
	public void add(GoodsBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(GoodsBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(GoodsBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getInfo(GoodsBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<GoodsBean>() {
		}.getType();
		String apiVer = "101";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("keyword", model.getKeyword());
		map.put("cate_id", model.getCate_id());
		map.put("uid", model.getUid());
		map.put("prop_id", model.getProp_id());
		map.put("page_size", model.getPage_size());
		map.put("page_index", model.getPage_index());

		(new Builder<GoodsBean>())
				.setTypeVerParamsAndReturnClass(FenYeQuery, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<GoodsBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public List<GoodsBean> query(GoodsBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void keyWordQuery(String key) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<GoodsBean>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("keyword", key);

		(new Builder<GoodsBean>())
				.setTypeVerParamsAndReturnClass(KeyWordQuery, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<GoodsBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void DetailQuery(String pid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<GoodsDetailBean>() {
		}.getType();
		String apiVer = "102";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", pid);
		(new Builder<GoodsDetailBean>())
				.setTypeVerParamsAndReturnClass(DetailQuery, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<GoodsDetailBean>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void AllQuery(String uid, String pageindex, String pagesize) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<GoodsTopBean>() {
		}.getType();
		String apiVer = "102";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("page_index", pageindex);
		map.put("page_size", pagesize);
		(new Builder<GoodsTopBean>())
				.setTypeVerParamsAndReturnClass(AllQuery, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<GoodsTopBean>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
